<?php 


/** 
***************************************************
*欢迎使用免费版xSite企业自助建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.php.net.cn/xsite/ 
***************************************************
**/




 class Captcha { var $font; function generateCode($characters) { $possible = '2346789bcefghjkmpqrtvwxy'; $code = ''; $i = 0; while ($i < $characters) { $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); $i++; } return $code; } function create_captchaImage($fontpath ='', $width='120', $height='40', $characters='6') { $font = $fontpath; $code = $this->generateCode($characters); $font_size = $height * 0.55; $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream'); $background_color = imagecolorallocate($image, 255, 255, 255); $text_color = imagecolorallocate($image, 20, 40, 100); $noise_color = imagecolorallocate($image, 200, 120, 180); for( $i=0; $i<($width*$height)/3; $i++ ) { imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color); } for( $i=0; $i<($width*$height)/150; $i++ ) { imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color); } if ($textbox = @imagettfbbox($font_size, 0, $font, $code)) { $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; } else { $x = $width - ($width - 15); $y = $height - 8; } if (!@imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code)) { $image_code = preg_split('//', $code, -1, PREG_SPLIT_NO_EMPTY); for ($i = 0 ; $i < count($image_code); $i++) { $image_code[$i] = SITE_DIR . "/templates/default/font/{$image_code[$i]}.gif"; $crop = imagecreatefromgif($image_code[$i]); imagecopy ( $image, $crop, ($i * 20) + 10, 8, 0, 0, 20, 25 ); imagedestroy($crop); } } session_start(); $_SESSION['captcha_code'] = $code; header('Cache-control: no-cache'); imagejpeg($image); imagedestroy($image); } } ?>